//
//  AboutYunDongController.m
//  YunDongGym
//
//  Created by lqq on 2018/4/19.
//  Copyright © 2018年 lqq. All rights reserved.
//


typedef NS_ENUM(NSInteger, AboutYDCellType) {
    AboutYDCellType_WeChatPublicNumber,//微信公众号
    AboutYDCellType_ContactInformation,//联系方式
    AboutYDCellType_CompanyWebset,//官方网站
};
#import "AboutYunDongController.h"
#import "CommonTableViewCell.h"
@interface AboutYunDongController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *dataSource;

@end

@implementation AboutYunDongController
+ (instancetype)controller
{
    AboutYunDongController *aboutVC = [[AboutYunDongController alloc] init];
    return aboutVC;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"关于云动";
    _dataSource = @[@[@(AboutYDCellType_WeChatPublicNumber),@(AboutYDCellType_CompanyWebset)]];
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = TP.controllerBackColor;
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    [tableView registerClass:[CommonTableViewCell class] forCellReuseIdentifier:@"CommonTableViewCell"];
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 120)];
    UIImageView *YDIcon = [[UIImageView alloc] init];
    YDIcon.layer.cornerRadius = 10;
    YDIcon.layer.masksToBounds = YES;
    YDIcon.image = IMG_NAME(@"ic_launcher_APP");
    [headerView addSubview:YDIcon];
    [YDIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.equalTo(headerView);
        make.height.width.equalTo(@(80));
    }];
    tableView.tableHeaderView = headerView;
}


#pragma mark UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *list = _dataSource[section];
    return list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CommonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CommonTableViewCell"];
    NSArray *list = _dataSource[indexPath.section];
    
    AboutYDCellType cellType = [list[indexPath.row] integerValue];
    switch (cellType) {
        case AboutYDCellType_WeChatPublicNumber:
        {
            cell.leftLabel.text = @"微信公众号";
            cell.showStyle = CommonTableViewShowStyleArrow_RightText;
            cell.rightLabel.text = @"云动助手";
        }
            break;
        case AboutYDCellType_ContactInformation:
        {
            cell.leftLabel.text = @"联系方式";
            cell.showStyle = CommonTableViewShowStyleArrow_RightText;
            cell.rightLabel.text = @"400-100-0002";
        }
            break;
        case AboutYDCellType_CompanyWebset:
        {
            cell.leftLabel.text = @"官方网站";
            cell.showStyle = CommonTableViewShowStyleArrow_RightText;
            cell.rightLabel.text = @"www.cloudfighting.com";
        }
            break;
        
            
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSArray *list = _dataSource[indexPath.section];
    AboutYDCellType cellType = [list[indexPath.row] integerValue];
    switch (cellType) {
        case AboutYDCellType_WeChatPublicNumber:
        {
            UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
            
            pasteboard.string = @"云动助手";
            [AV showSuccess:@"已添加到剪切板"];
        }
            break;
        case AboutYDCellType_ContactInformation:
        {

        }
            break;
        case AboutYDCellType_CompanyWebset:
        {
            YDWebViewController *webVC = [YDWebViewController controllerWithUrl:@"http://www.cloudfighting.com"];
            [self.navigationController pushViewController:webVC animated:YES];
        }
            break;

        default:
            break;
    }
}
@end
